package com.hspedu.homework.homework08;

/**
 * 扩展前一个练习的BankAccount类，
 * 新类SavingsAccount每个月都有利息产生(earnMonthlyInterest方法被调用)，
 * 并且有每月三次免手续费的存款或取款。在earnMonthlyInterest方法中重置交易计数
 */
public class SavingAccount extends BankAccount{
    private double rate = 0.01;//利率
    private int count = 3;

    public SavingAccount(double initialBalance) {
        super(initialBalance);
    }

    @Override
    public void deposit(double amount) {
        if (count>0){
            super.deposit(amount);
        }else{
            super.deposit(amount-1);
        }
        count --;//免手续费次数-1
    }

    @Override
    public void withdraw(double amount) {
        if (count>0){
            super.withdraw(amount);
        }else {
            super.withdraw(amount+1);
        }
        count --;
    }

    public void earnMonthlyInterest(){
        count = 3;//每月重置交易计数
        super.deposit(getBalance()*rate);
    }
}
